#include "qmylistview.h"

#include <QVariant>

QListViewHost::QListViewHost(QWidget *wid):
    QObjectHost(wid)
{
}

int QListViewHost::currentRow()
{
    return ((QMyListView*)m_widget)->currentIndex().row();
}


QMyListView::QMyListView(QWidget *parent):
    QListWidget(parent),
    m_host(new QListViewHost(this))
{
    setProperty("className","QListView");
    setProperty("typeName","List View");
    setProperty("typeIcon",":/images/widgets/listbox.png");
    setProperty("objectName","listView");


}

void QMyListView::updateProperty(const QString & name)
{
    if(name=="Z-Value")
    {
        emit zValueChanged();
    }
}

void QMyListView::updatePropertyAttribute()
{
    m_host->updatePropertyAttribute();
}

void QMyListView::initProperty()
{
    if(property("running").toBool())
    {
        m_host->setGlobalObject(sender());
        m_host->initRunningProperty();
    }
}

void QMyListView::addItem(const QString &text)
{
    QListWidgetItem *item;
    item=new QListWidgetItem(this);
    item->setText(text);
    item->setToolTip(text);
}

void QMyListView::insertItem(int index, const QString &text)
{
    this->insertItems(index,QStringList()<<text);
}

void QMyListView::removeItem(int index)
{
    QListWidgetItem *item=takeItem(index);
    delete item;
}

void QMyListView::setCurrentRow(int index)
{
    this->setCurrentItem(this->item(index));
}
